﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using QLK.Database.BLLs;
using QLK.Web.App_Code;
using QLK.Database;

namespace QLK.Web
{
    public partial class InvoicesProductManagement : System.Web.UI.Page
    {
        public int _iStt = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                LoadAllInvoicesProduct();
            }
        }
        private void LoadAllInvoicesProduct()
        {
            InvoicesProductBLL bll = new InvoicesProductBLL();
            GridInvoiceProduct.DataSource = bll.GetAllInvoiceProduct();
            GridInvoiceProduct.DataBind();
        }
        protected void btnAdd2_Click(object sender, EventArgs e)
        {
            Response.Redirect(PageUrls.InvoicesProductDetails);
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect(PageUrls.SupplierDetails);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            Invoices_Product pro = new Invoices_Product();
            InvoicesProductBLL inproBLL = new InvoicesProductBLL();
            int productID;
            foreach (GridViewRow row in GridInvoiceProduct.Rows)
            {
                CheckBox check = (CheckBox)row.FindControl("chkSelect");
                if (check.Checked)
                {
                    productID =int.Parse(GridInvoiceProduct.DataKeys[row.RowIndex].Value.ToString());
                    pro.ProductID = productID;

                    inproBLL.DeleteInvoiceProductByProductID(productID);
                }
            }
            LoadAllInvoicesProduct();
            
        }
    }
}
